package Dxc;

//静态代理
public class StaticProxy {
    public static void main(String[] args) {

        You you = new You();
        you.happyMarry();
        System.out.println("\t下面是代理结婚的结果:");
        WeddingCompany weddingCompany = new WeddingCompany(you);
        //下面的happyMarry相当于多线程的start
        weddingCompany.happyMarry();
    }

}

interface Marry {
    void happyMarry();
}

class You implements Marry {
    @Override
    public void happyMarry() {
        System.out.println("你结婚Le.");
    }
}

class WeddingCompany implements Marry {
    //这里是代理的真实目标角色
    private Marry target;//不太理解

    public WeddingCompany(Marry target) {
        this.target = target;
    }

    @Override
    public void happyMarry() {
        before();
        this.target.happyMarry();//此为真实对象
        after();
    }

    private void before() {
        System.out.println("结婚前，准备");
    }

    private void after() {
        System.out.println("结婚后，成家");
    }
}
